﻿//-------------------------------------
// WBFSSync - WBFSSync.exe
//
// Copyright 2009 Caian (ÔmΣga Frøst) <frost.omega@hotmail.com> :
//
// WBFSSync is Licensed under the terms of the Microsoft Reciprocal License (Ms-RL)
//
// FormLoaderHOmebrewEdit.cs:
//
// Diálogo para edição de Esquemas de Loaders
//
//-------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WBFSSync
{
    public partial class FormLoderHomebrewEdit : Form
    {

        public FormLoderHomebrewEdit()
        {
            InitializeComponent();
        }

        public void SetupLanguage()
        {
            this.Text = Language.field_form_name_edit_loader;
            label_name.Text = Language.field_name;
            label_path.Text = Language.field_path;
            label_width.Text = Language.field_width;
            label_height.Text = Language.field_height;
            button_ok.Text = Language.field_ok;
            button_cancel.Text = Language.field_cancel;
        }

        private void FormLoderHomebrewEdit_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                //Valida o nome
                if (textBox_name.Text.Contains('|'))
                {
                    MessageBox.Show(this, String.Format(Language.message_invalid_chars, Language.field_name), Language.AppName,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                //Valida o caminho
                Char[] invalid = Path.GetInvalidPathChars();
                if (textBox_path.Text.IndexOfAny(invalid) >= 0)
                {
                    MessageBox.Show(this, String.Format(Language.message_invalid_chars, Language.field_path), Language.AppName,
                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    return;
                }

                //Converte separador / para \
                textBox_path.Text = textBox_path.Text.Replace('/', '\\');

                if (textBox_path.Text.Length == 1)
                {
                    if (textBox_path.Text[0] == '\\')
                        textBox_path.Text = "";
                    else
                        textBox_path.Text += '\\';

                }
                else if (textBox_path.Text.Length >= 3)
                {
                    if ((textBox_path.Text[1] == ':') && (textBox_path.Text[2] == '\\'))
                    {
                        textBox_path.Text = textBox_path.Text.Substring(3);
                    }

                    if (!textBox_path.Text.EndsWith("\\") && textBox_path.Text.Length > 0)
                        textBox_path.Text += '\\';
                }
            }
        }
    }
}
